import 'package:banyou_app/app/config/colors.dart';
import 'package:banyou_app/app/request/request_main.dart';
import 'package:banyou_app/app/routes/app_pages.dart';
import 'package:banyou_app/app/util/common_utils.dart';
import 'package:banyou_app/app/widget/app_bar_widget.dart';
import 'package:banyou_app/app/widget/delete_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_html/flutter_html.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import 'package:get/get.dart';

import '../controllers/zhuxiao_controller.dart';

class ZhuxiaoView extends GetView<ZhuxiaoController> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Stack(
        children: [
          Positioned(
            top: 0,
            left: 0,
            right: 0,
            height: 1.sw * 264 / 378,
            child: Image.asset(
              'assets/images/图像 25@2x.png',
              width: 1.sw,
            ),
          ),
          Positioned(
            top: 100,
            left: 25,
            right: 25,
            child: Container(
              clipBehavior: Clip.hardEdge,
              decoration: BoxDecoration(
                border: Border.all(color: Color(0x1A131313)),
                color: ColorConfig.white,
                borderRadius: BorderRadius.all(Radius.circular(10.r)),
              ),
              padding: EdgeInsets.symmetric(horizontal: 30, vertical: 30),
              child: Column(
                children: [
                  Image.asset(
                    'assets/images/uu@2x.png',
                    width: 86,
                    height: 86,
                  ),
                  SizedBox(width: 10),
                  Text("注销用户",
                      style: TextStyle(
                          color: ColorConfig.text_label,
                          fontWeight: FontWeight.bold,
                          fontSize: 16)),
                  SizedBox(height: 10),
                  Obx(() => Html(data: controller.tip.value)),
                  const SizedBox(height: 30),
                ],
              ),
            ),
          ),
          Positioned(
            top: 0,
            left: 0,
            right: 0,
            height: 60,
            child: AppBarWidget(
              titleStr: '注销账户',
              backgroundColor: Colors.transparent,
            ),
          ),
          Positioned(
            bottom: 20,
            left: 0,
            right: 0,
            height: 45,
            child: InkWell(
              child: Container(
                margin: EdgeInsets.symmetric(horizontal: 51),
                height: 45,
                decoration: BoxDecoration(
                  gradient: LinearGradient(
                      begin: Alignment.centerLeft,
                      end: Alignment.centerRight,
                      colors: [
                        Color(0xFFF52EC5),
                        Color(0xFFFF8A33),
                      ]),
                  borderRadius: BorderRadius.circular(20),
                ),
                child: Center(
                  child: Text(
                    "确定注销",
                    style: TextStyle(
                        color: ColorConfig.white,
                        fontSize: 16,
                        fontWeight: FontWeight.w500),
                  ),
                ),
              ),
              onTap: () {
                Get.dialog(
                        DeleteDialogView(
                            '确定要注销用户吗？', 'assets/images/组 84@2x.png'),
                        barrierColor: Colors.black.withAlpha(100))
                    .then((value) async {
                  if (value == 1) {
                    EasyLoading.show(status: '注销中...');
                    Map? m1 = await RequestMain.postUrl(
                        {"cancel_member": box.read('mobile')},
                        turl: 'https://aqbanyou.olbibo.com.cn/sign/?a=index');
                    if (m1.isNotEmpty && m1['code'].toString() == "200") {
                      await box.remove('key');
                      await box.remove('kefu');
                      await box.remove('tab');
                      await box.remove('mobile');

                      Get.offAndToNamed(Routes.LOGIN);
                      // Get.find<TableController>().loadSet();
                      EasyLoading.showToast('注销成功');
                      // Get.toNamed(Routes.LOGIN);
                    } else {
                      EasyLoading.dismiss();
                    }
                  }
                });
              },
            ),
          ),
        ],
      ),
    );
  }
}
